package sicnu.cs.ich.activity.aop;

import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import sicnu.cs.ich.activity.service.IActivityRankService;
import sicnu.cs.ich.api.domain.entity.Activities;
import sicnu.cs.ich.api.domain.vo.ActivityDetailVO;

/**
 * @author 黎琦
 * @date 2021/12/23 15:11
 **/
@Aspect
@Slf4j
@Component
@RequiredArgsConstructor
public class ActivityHitAOP {
    private final IActivityRankService activityRankService;
    /**
     * 拦截统计活动/号召热度
     *
     * @param activityDetailVO
     */
    @AfterReturning(value = "execution(public * sicnu.cs.ich.activity.service.IActivityService.getActivityDetail(..))",returning = "activityDetailVO")
    public void doBeforeSelectActivity(ActivityDetailVO activityDetailVO) throws InterruptedException, RemotingException, MQClientException, MQBrokerException, JsonProcessingException {
        Activities activities = activityDetailVO.getActivities();
        //区分是活动还是号召
        if(activities.getIsCallUpon()==0){
            //活动
            activityRankService.activityHitIncrement(activities.getId());
        }else{
            //号召
            activityRankService.callHitIncrement(activities.getId());
        }
    }
}
